// @flow
/**
 * 适配工具类
 */
import { Dimensions, Platform, StatusBar } from "react-native";

const X_WIDTH = 375;
const X_HEIGHT = 812;

const XSMAX_WIDTH = 414;
const XSMAX_HEIGHT = 896;

const { height: W_HEIGHT, width: W_WIDTH } = Dimensions.get("window");

let isIPhoneX = false;

if (Platform.OS === "ios" && !Platform.isPad && !Platform.isTVOS) {
  isIPhoneX =
    (W_WIDTH === X_WIDTH && W_HEIGHT === X_HEIGHT) ||
    (W_WIDTH === XSMAX_WIDTH && W_HEIGHT === XSMAX_HEIGHT);
}

/**
 *  Android和IOS头部适配
 * @param {*} skipAndroid {boolean} 是否高度默认为导航栏高度
 * @param {*} height {number} 如不是默认导航栏高度，则可以自定义设置高度（默认为0）
 */
export function getStatusBarHeight(skipAndroid = false, height = 0) {
  return Platform.select({
    ios: isIPhoneX ? 44 : 20,
    android: skipAndroid ? height : StatusBar.currentHeight,
    default: 0,
  });
}
